import {reqCategoryList,reqBannerList,reqFloorList} from '@/api'
//四大核心属性
//state :仓库的数据来源
const state = {
    categoryList:[],
    //轮播图的数据
    bannerList:[],
    //floor的数据
    floorList:[],
};
//mutation:唯一改变state数据的地方
const mutations = {
    GETCATEGORY(state,bannerList){
        state.categoryList = bannerList;
    },
    GETBANNER(state,floorList){
        state.bannerList = floorList;
    },
    GETFLOORLIST(state,result){
        state.floorList = result
    }
}
//actions:可以处理dispatch 派发 action 的地方，这里可以书写你的业务逻辑
//for if 异步语句等等
const actions ={
    async getCategory({commit}){
       let result = await reqCategoryList();
     if(result.code == 200){
        commit('GETCATEGORY', result.data)
     }// console.log(result.data)测试是否请求回来的数据
    },
    //获取banner首页轮播图的数据
   async  getBannerList({commit}){
      let result = await  reqBannerList();
      //测试获取数据打印在控制台上
    //   console.log(result)
    if(result.code == 200){
        commit('GETBANNER',result.data)
    }  
    },
           //获取Floor的数据
    async  getFloorList({commit}){
       let result = await reqFloorList();
       //测试打印floor数据在控制台上
    //    console.log(result.data)
            if(result.code == 200){
                commit('GETFLOORLIST',result.data);
            }
    }
}
const getters = {

}

export default {
    state,
    mutations,
    actions,
    getters
}